<?php
namespace Shopmanage\Controller;
use Think\Controller;
class ChajianController extends ExtendController {
	public function index(){
		$TOOL = D("CheckTools");
		$TOOL->sid = $this->sid;
		$tool = $TOOL->ShowTools();
		$TOOL->ToolName = "互动折扣";
		$TOOL->UserNick = $this->usernick;
		$TOOL->IsvCode = "FW_GOODS-1840332";
		// $TOOL->CheckISV();
		// print_r($TOOL->tool["days"]);
		
		$this->assign("isv",$TOOL->tool);
		$this->assign("tool",$tool);
		$this->assign("title","插件管理");
		$this->assign("current","chajian");
		$this->display();
	}	
	public function assigntool(){
		$return = I("return");
		$r = I("r");
		$toolname = I("toolname");
		$lowversion = I("lowversion");
		$Chk = D("CheckTools");
		if($Chk->myfilter($toolname)){
			$tool_type = $Chk->GetToolType($toolname);
			$Chk->sid=$this->sid;
			$Chk->toolid=$Chk->GetToolID($toolname);
			$Chk->_addtool();
			$data["msg"] = $Chk->err;
			/*
			暂取消ISV订购判断。应在登陆时记录订购信息。
						
						$Chk->UserNick = $this->usernick;
						$Chk->IsvCode = C("SM_CODE");
						$Chk->CheckISV();
						// $Chk->item_code=C("SM_CODE").'-2';
						// $Chk->deadline="2016-03-12 19:00:00";
						if($Chk->item_code==C("SM_CODE").'-2' ){
							if($tool_type==3||$tool_type==1){
								$Chk->sid=$this->sid;
								$Chk->toolid=$Chk->GetToolID($toolname);
								$Chk->lowversion=$lowversion?true:false;
								if($Chk->AssignTool()){
									$data['status']=true;
									$data['msg']='成功开通！';
								}else{
									$data['status']=false;
									$data['msg']="err".$Chk->err;
								}
							}else{
								$data['status']=false;
								$data['msg']='未知的工具类型';
							}
						}elseif($Chk->item_code==C("SM_CODE").'-1'){
							// if($tool_type ==1){  暂取消版本判断
								// 判断版本类型，普及版所有用户可开通。-1为普通版，-2为游戏版/风尚版
								$Chk->sid=$this->sid;
								$Chk->toolid=$Chk->GetToolID($toolname);
								if($Chk->AssignTool()){
									$data['status']=true;
									$data['msg']='成功开通！';
								}else{
									$data['status']=false;
									$data['msg']='err-1'.$Chk->err;
								}
							// }else{
								// $data['status']=false;
								// $data['msg']='您尚未订购游戏版，仅游戏版可开通本工具。<a class="button" href="http://fuwu.taobao.com/service/service.htm?service_code=ts-30901&f=upgrad" target="_blank" >立即订购</button><a href=""></a>';
							// }
						}
			*/
		}else{
			$data['status']=false;
			$data['msg']='您要开通的工具不存在';
		}
		if($return=="msg"){
			$this->success("提示信息：".$data["msg"],$r?"/?c=chajian&m=shopmanage":"/?a=gamecfg&m=shopmanage&repick=1");
		}else{
			$this->ajaxReturn($data);
		}
	}
}